<template>
    <div >
        <!-- 申请 -->
        <div class="consulting-service" style="padding: 0px 10px; text-align: left">
            
            <van-icon name="arrow-left" size="8vw" color="#000" @click="$router.push('/')" />
            <!-- 题目 -->
            <h2 style="text-align: center; padding: 20px" class="bcl">志愿者申请</h2>
            <ul>
                <li >探索可可西里│志愿者行动</li>
                <li>向可可西里守护者致敬！</li>
                <li>您好：</li>
                <li>按照要求填写，申请完成后我们將尽快与您联系！</li>
            </ul>
            <!-- 过程 -->
            <div>
                <van-steps :active="active" active-color="#E6A145">
                    <van-step>基本信息</van-step>
                    <van-step>申请理由</van-step>
                    <van-step>凭证图片</van-step>
                    <van-step>申请完成</van-step>
                </van-steps>
            </div>
            
        <!-- 输入内容一 -->
        <van-form >
                <div class="contact-information" style="margin-bottom: 20px" v-show="active==0 || active==3 ">
                <div style="padding-bottom: 10px;">基本信息</div>
                <p class="bcl">1.真实姓名</p>
                <van-field type="text" v-model="form.name" />
                <p class="bcl">2.电话</p>
                <input type="text"  v-model="form.phone" />
                <p class="bcl">3.职位</p>
                <input type="text" v-model="form.position" />
                <div>
                    <p class="bcl">4.当前地区</p>
                    <van-field
                    readonly
                    clickable
                    name="area"
                    :value="value"
                    placeholder="点击选择省市区"
                    @click="showArea = true"
                    />
                    <van-popup v-model="showArea" position="bottom">
                    <van-area
                        :area-list="areaList"
                        @confirm="onConfirm"
                        @cancel="showArea = false"
                    />
                    </van-popup>
                </div>
                <p class="bcl">5.是否自愿参加可可西里自愿者</p>
                <br>
                <van-switch v-model="form.isno" size="30px" active-color="#E6A145" inactive-color="#dcdee0" />   
            </div>
            <!--  输入内容二  -->
            <div v-show="active==1|| active==3 ">
                <van-field
                v-model="form.reason"
                rows="10"
                autosize
                label="申请理由："
                type="textarea"
                maxlength="200"
                placeholder="请输入申请理由"
                show-word-limit
                />
            </div>
            <!--  输入内容三  -->
            <div v-show="active==2|| active==3 ">
                <el-upload
                :limit="4"
                :on-exceed="handleExceed"
                :action="`${UPLOADURL}upload`"
                list-type="picture-card"
                :on-success="handleMovieSuccess"
                :on-preview="handlePictureCardPreview"
                :on-remove="handleRemove">
                    <i class="el-icon-plus"></i>
                </el-upload>
                <el-dialog :visible.sync="dialogVisible">
                    <img width="100%" :src="dialogImageUrl" alt="">
                </el-dialog>
            </div>
            </van-form>
            

            <van-button 
                v-show=" active !=3 "
                @click="submit"
                type=""
                block
                style="margin-bottom: 50px"
                class="bcl"
                color="#E6A145"
                >下一步</van-button
            >
            <van-button 
                v-show=" active==3 "
                @click="onsubmit"
                type=""
                block
                style="margin-bottom: 50px"
                class="bcl"
                color="#E6A145"
                >提交</van-button
            >
        </div>
    </div>
    
</template>

<script>
import httpApi from "@/http";
import area from "@/views/Mobile/user/area";
import Vue from 'vue';
import { Notify  } from 'vant';

export default {
    components: {
        [Notify.Component.name]: Notify.Component,
    },
    data() {
        return {
            form:{
                user_id:this.$store.state.uid || 7 ,
                name:'',
                phone:'',
                // 职位
                position:'',
                // 居住地
                region: '',
                isno:'',
                reason:'',
                img:[],
            },
            // 过程图
            active: 0,

            // 地区
            value: '',
            showArea: false,
            areaList: area.AddressInfo, 
            //  图片
            dialogImageUrl: '',
            dialogVisible: false,
             
        }
    },
    methods: {
        //图片
        // 删除
        handleRemove(file, fileList) {
            console.log(file, fileList);   
        },
        handleMovieSuccess(res, file) {
            // console.log(res)
            // 将上传成功后的图片访问路径，存入form对象
            this.form.img.push(`${res.data}`) 
        },
        // 添加
        handlePictureCardPreview(file) {
            this.dialogImageUrl = file.url;
            this.dialogVisible = true;
            console.log(this.dialogImageUrl);
        },
        // 错误
        handleExceed(files, fileList) {
            this.$message.warning(`当前限制选择 4 个文件，共选择了 ${files.length + fileList.length} 个文件`);
        },

        // 地区
        onConfirm(values) {
        this.value = values
            .filter((item) => !!item)
            .map((item) => item.name)
            .join('/');
        this.showArea = false;
        },
        // 下一步
        submit() {
            this.active++
        },
        // 提交
        onsubmit(){
            this.form.region = this.value
            this.form.img = this.form.img.join(',')
            // console.log(this.form);
            httpApi.ApplyApi.add(this.form).then(res =>{
                console.log("添加申请",res);
                if(res.data.code == 200){
                    Notify({ type: 'success', message: '提交成功' });
                }else if(res.data.code == 400){
                    Notify({ type: 'warning', message: '请填写完整' });
                }else{
                    Notify({ type: 'danger', message: '提交失败' });

                }
            })
        }
    },
};
</script>
<style scoped src="@/assets/css/appointment.css">

</style>
<style lang="scss" scoped>
.consulting-service {
    ul {
        li {
            padding: 5px 0;
        }
    }
    .bcl {
        color: #000;
       
    }
}

.contact-information {
    margin: 20px 0;
    margin-top: 3vw;
    border: 1px solid white;
    background-color: white;
    border-radius: 7px;
    // box-shadow:3px 5px ghostwhite ;
    padding: 8px;
    input {
        width: 80vw;
        height: 30px;
        border: 1px solid gray;
        border-radius: 5px;
        margin: 10px 0;
        padding:0 5px;
    }
    ::v-deep .van-cell{
        width: 84vw;
        height: 35px;
        border: 1px solid gray;
        border-radius: 5px;
        margin: 10px 0;
        padding:0 5px;
    }
}
.preview-cover {
    position: absolute;
    bottom: 0;
    box-sizing: border-box;
    width: 100%;
    padding: 4px;
    color: #fff;
    font-size: 12px;
    text-align: center;
    background: rgba(0, 0, 0, 0.3);
  }
  ::v-deep .van-uploader__upload{
    width: 90vw;
    height: 50vw;
    margin: 5px;
  }
.van-button--block {
    border: 1px solid gray;
    border-radius: 5px;
}

</style>
